package com.xiao.classloader;

/**
 * 初探 java 类加载器
 */
public class ClassLoaderTest {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        ClassLoader sysClassLoad = ClassLoader.getSystemClassLoader();
        Class<?> myClazz = sysClassLoad.loadClass("com.xiao.classloader.MyClass");
        MyClass myClaObj = (MyClass)myClazz.newInstance();
        myClaObj.showProp();

        // 动态创建代理类时，可以指定类加载器


    }
}

class MyClass {

    private static String staticProp;
    private String prop;

    static {
        staticProp = "静态属性，静态代码块内赋值";
    }

    {
        prop = "非静态属性，非静态代码块中赋值";
    }

    public static void showStaticProp() {
        System.out.println(staticProp);
    }

    public void showProp() {
        System.out.println(prop);
    }


}
